package com.lawyer.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.lawyer.common.StringUtil;
import com.lawyer.common.result.Result;
import com.lawyer.common.result.ResultFactory;
import com.lawyer.constant.Status;
import com.lawyer.model.ConsultUserInfo;
import com.lawyer.service.ConsultUserInfoService;
import com.lawyer.vo.GetOpenIdVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 用户咨询表 前端控制器
 * </p>
 *
 * @author D.Wzq
 * @since 2018-07-18
 */
@RestController
@RequestMapping("/consultUserInfo")
public class ConsultUserInfoController {

    @Autowired
    ConsultUserInfoService consultUserInfoService;
    /**
     * 获取用户OPENID
     * @author wzq
     */
    @PostMapping("/getLawUserOpenId")
    @ResponseBody
    public Result getOpenId(@RequestBody GetOpenIdVo openIdVo){
        if(StringUtil.isEmpty(openIdVo.getCode())){
            return ResultFactory.result(Status.BAD_REQUEST, "参数不可为空");
        }
        return ResultFactory.result(Status.SUCCESS,Status.SUCCESS_MSG);
    }

    @GetMapping(value = "/getClientInfoListPage/{pageSize}/{pageNo}")
    @ResponseBody
    public Result getClientInfoListPage(
            @PathVariable("pageSize") int pageSize,
            @PathVariable("pageNo") int pageNo,
            GetOpenIdVo queryDto){
        Page<ConsultUserInfo> page = new Page<>(pageNo,pageSize);
        Map<String,Object > mapList = new HashMap<>();
        try{
            String startTime = queryDto.getCode();
            String endTime= queryDto.getAbbreviation();


            if(!StringUtil.isEmpty(startTime)) {
                startTime += " 00:00:00";
            }

            if(!StringUtil.isEmpty(endTime)) {
                endTime += " 23:59:59";
            }

            Long company = 1l;
            EntityWrapper<ConsultUserInfo> consultUserInfoEntityWrapper= new EntityWrapper<>();
            consultUserInfoEntityWrapper.eq("consult_user_id",5);

            //获取客户信息列表信息
            List<ConsultUserInfo> list = consultUserInfoService.selectList(consultUserInfoEntityWrapper);

            mapList.put("queryDto",queryDto);
            mapList.put("list", list);
            mapList.put("page", page);
        }catch(Exception e){
            //LoggerUtil.error(logger, e, "sendRegisterVCode-获取失败");
            return ResultFactory.result(Status.BAD_REQUEST, e.getMessage());
        }
        return ResultFactory.successData(mapList);
    }
	
}
